//
// Created by jerry on 2024/10/11.
//
#include "vector.h"
#include "list.h"
#ifndef DATASTRUCTURE_STACK_H
#define DATASTRUCTURE_STACK_H
namespace mycode{
    template<class T,class Container = mycode::list<T>>
    class stack{
    public:
        using Self = stack<T,Container>;
        using Ref = stack<T,Container>&;
        using Ptr = stack<T,Container>*;
        bool empty() const { return _con.empty(); }
        size_t size() const { return _con.size(); }

        explicit stack() = default;
        explicit stack(const Ref sk):_con(sk._con)
        {}
        explicit stack(stack<T,Container>&& sk)
            :_con(std::move(sk._con))
        {}
        Ref operator=(const Ref sk){
            _con = sk._con;
            return *this;
        }
        Ref operator=(stack<T,Container>&& sk){
            _con = std::move(sk._con);
            return *this;
        }
        template <class Elem>
        void push(Elem&& val){ _con.push_back(std::forward<Elem>(val));}
        void pop(){
            _con.pop_back();
        }
        T& top(){ return _con.back();}
        const T& top() const { return _con.back();}
        //基于stack的理念,这里不用使用迭代器也不能使用迭代器

    private:
        Container _con;
    };
}
#endif //DATASTRUCTURE_STACK_H
